﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using MM.Common.Base;
using DevExpress.XtraTab;

namespace MM.Common.UI.Controls
{
    public class UCTabPage : XtraTabPage, IControlProperty
    {
        // Fields
        private string _ControlCode;
        private string _ControlName;
        private EControlPropertyStatus _ControlProperty;
        private IContainer components;

        // Methods
        public UCTabPage()
        {
            this.InitializeComponent();
        }

        public UCTabPage(IContainer container)
        {
            container.Add(this);
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
        }

        // Properties
        [Browsable(true), Description("控制本控件对应的系统代码"), DefaultValue((string)null), Category("MM附加")]
        public string ControlCode
        {
            get
            {
                return this._ControlCode;
            }
            set
            {
                this._ControlCode = value;
            }
        }

        [DefaultValue((string)null), Category("MM附加"), Description("控制本控件对应的系统名称"), Browsable(true)]
        public string ControlName
        {
            get
            {
                return this._ControlName;
            }
            set
            {
                this._ControlName = value;
                if (!base.DesignMode && !string.IsNullOrEmpty(this.ControlCode))
                {
                    if (this._ControlProperty == EControlPropertyStatus.None)
                    {
                        this._ControlProperty = BaseDataHelper.GetFunctionPointProperty(this._ControlCode, this._ControlName);
                    }
                    switch (this._ControlProperty)
                    {
                        case EControlPropertyStatus.Read:
                            this.PageEnabled = false;
                            this.PageVisible = true;
                            return;

                        case EControlPropertyStatus.Write:
                            this.PageEnabled = true;
                            this.PageVisible = true;
                            return;
                    }
                    this.PageVisible = false;
                }
            }
        }

        [Browsable(false), DefaultValue(0)]
        public EControlPropertyStatus ControlProperty
        {
            get
            {
                return this._ControlProperty;
            }
            set
            {
            }
        }

        public override bool PageEnabled
        {
            get
            {
                return base.PageEnabled;
            }
            set
            {
                base.PageEnabled = value;
                if ((!string.IsNullOrEmpty(this.ControlCode) && (this.ControlProperty != EControlPropertyStatus.Write)) && base.PageEnabled)
                {
                    base.PageEnabled = false;
                }
            }
        }

        public override bool PageVisible
        {
            get
            {
                return base.PageVisible;
            }
            set
            {
                base.PageVisible = value;
                if ((!string.IsNullOrEmpty(this.ControlCode) && (this.ControlProperty == EControlPropertyStatus.Hide)) && base.PageVisible)
                {
                    base.PageVisible = false;
                }
            }
        }
    }
}
